
$('form').validate({
    rules: {
        username: {
            required: true,
            rangelength: [5, 10]
        },
        password: {
            required: true,
            rangelength: [5, 10]
        },
    },
    messages: {
        username: {
            required: '请输入账号',
            rangelength: '输入长度必须介于5和10位'
        },
        password: {
            required: '请输入密码',
            rangelength: '输入长度必须介于5和10位'
        }
    },
    submitHandler(form) {
        $.ajax({
            url: './severs/login.php',
            type: 'post',
            data: {
                username: $('input[name="username"]').val(),
                password: $('input[name="password"]').val()
            },
            dataType: 'json',
            success(res) {
                if (res.statu == 2) {
                    if($('.free').prop("checked")==true){
                        setCookie('username',$('input[name="username"]').val(),7)
                    }
                    else{
                        document.cookie=`username=${$('input[name="username"]').val()}`;
                    }
                    alert(res.msg)
                    location.href = "./indexs.html"
                }
                if (res.statu == 1) {
                    alert(res.msg)
                    return false;
                }
                if (res.statu == 0) {
                    alert(res.msg)
                    return false;
                }
            }
        })
    }
})
$('button').click(function () {
    location.href = "./register.html"
})